[id].vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 页面导航 -->
  6. <HomePageNavigation></HomePageNavigation>
  7. <!-- 面包屑导航 -->
  8. <div class="breadcrumb">
  9. <div class="inner">
  10. <span class="location">当前位置:</span>
  11. <el-breadcrumb :separator-icon="ArrowRight">
  12. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  13. <el-breadcrumb-item>{{ name }}</el-breadcrumb-item>
  14. </el-breadcrumb>
  15. </div>
  16. </div>
  17. <!-- 资讯列表 -->
  18. <div class="newsList">
  19. <div class="inner">
  20. <div class="innerLeft">
  21. <ul class="list">
  22. <li v-for="(item, index) in newsList" :key="index">
  23. <!-- <NuxtLink :to="item.linkurl" target="_blank" v-show="item.islink == 1">
  24. <span class="list1">{{ item.title }} </span>
  25. </NuxtLink> -->
  26. <NuxtLink :to="`/newsDetail/${item.id}`" target="_blank">
  27. <span class="listTitle">{{ item.title }}</span>
  28. <span class="time">02-16</span>
  29. </NuxtLink>
  30. </li>
  31. </ul>
  32. <!-- 分页器 -->
  33. <div class="pagination" v-if="total">
  34. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  35. v-model:page-size="pageSize" prev-text="上一页" next-text="下一页" @change="changePage" />
  36. </div>
  37. </div>
  38. <div class="innerRight">
  39. <DetailHotNews></DetailHotNews>
  40. <DetailHotNews2></DetailHotNews2>
  41. </div>
  42. </div>
  43. </div>
  44. <!-- 列表页广告二 -->
  45. <HomeTopTenTitle :imgurl="adList[1]" v-if="adList[1]"></HomeTopTenTitle>
  46. <!-- 页面底部 -->
  47. <HomeFoot></HomeFoot>
  48. </div>
  49. </template>
  50. <script setup>
  51. import { onMounted } from 'vue';
  52. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  53. import { ArrowRight } from '@element-plus/icons-vue'
  54. const nuxtApp = useNuxtApp();
  55. const axios = nuxtApp.$axios;
  56. //获得跳转过来的id
  57. const route = useRoute();
  58. const articleId = route.params.id; //获得该页面的id
  59. // const category_id = route.query.category_id; //获得该页面的id
  60. const category_id = route.query.catid; //获得该页面的id
  61. // const name = route.query.name; //获得该页面的id
  62. // console.log(name);
  63. console.log('category_id', category_id);
  64. // 定义响应式数据
  65. const seoData = ref({
  66. title: '三农资讯网',
  67. description: '默认描述',
  68. keywords: '默认关键词',
  69. image: 'https://example.com/default-image.jpg'
  70. });
  71. // 在 onMounted 钩子中获取数据
  72. onMounted(async () => {
  73. try {
  74. const response = await axios.get(`/web/getWebsiteCategoryHead?catid=${articleId}`);
  75. const data = response.data; // 假设接口返回的数据在 data 字段中
  76. console.log(seoData.value.title)
  77. // 更新 seoData
  78. seoData.value = {
  79. title: data.seo_title,
  80. description: data.seo_description,
  81. keywords: data.seo_keywords,
  82. image: data.seo_image
  83. };
  84. console.log(seoData.value.title)
  85. } catch (error) {
  86. console.error('获取 SEO 数据失败:', error);
  87. // 设置默认值
  88. seoData.value = {
  89. title: '三农资讯网',
  90. description: '默认描述',
  91. keywords: '默认关键词',
  92. image: 'https://example.com/default-image.jpg'
  93. };
  94. }
  95. });
  96. // 监听 seoData 的变化,动态设置 SEO 字段
  97. watch(seoData, (newVal) => {
  98. if (newVal.title) { // 确保 title 有值
  99. useSeoMeta({
  100. title: newVal.title, // 使用动态值
  101. description: newVal.description,
  102. ogTitle: newVal.title,
  103. ogDescription: newVal.description,
  104. ogImage: newVal.image,
  105. twitterTitle: newVal.title,
  106. twitterDescription: newVal.description,
  107. twitterImage: newVal.image,
  108. keywords: newVal.keywords
  109. });
  110. }
  111. }, { immediate: true });
  112. //关键词
  113. let keyWord = useState("keyWord", () => "")
  114. let id = useState("id", () => "")
  115. let total = useState("total", () => 0)
  116. let page = useState("page", () => 1)
  117. let pageSize = useState("pageSize", () => 20)
  118. //获得广告
  119. const adList = ref("");
  120. const aa = 'LIST'
  121. const getadList = async () => {
  122. try {
  123. const response = await axios.get(`/web/getWebsiteAdvertisement?ad_tag=${aa}`);
  124. adList.value = response.data;
  125. } catch (error) {
  126. console.error(error);
  127. }
  128. }
  129. onMounted(() => {
  130. id.value = route.query.id;
  131. console.log('id', id.value);
  132. getadList()
  133. })
  134. // 页码
  135. // //页面组件传递数据的时间驱动函数
  136. // const handleData = (data) => {
  137. // console.log(data.value)
  138. // page.value = data.value
  139. // //在页码发生变化时去请求响应页面的新闻数据
  140. // axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${10}&catid=${14}&keyword=${keyWord.value}`).then(response => {
  141. // // console.log(response.data.rows);
  142. // newsList.value = response.data.rows;
  143. // }).catch(error => {
  144. // console.error(error);
  145. // })
  146. // }
  147. let changePage = (value) => {
  148. console.log("当前页码", value);
  149. page.value = value
  150. console.log(page.value);
  151. newslists()
  152. }
  153. // 一级导航
  154. const navigation1 = ref("");
  155. const navigateList = async () => {
  156. try {
  157. const response = await axios.get(`/web/getWebsiteModelCategory?placeid=${1}&pid=${0}&num=${24}`);
  158. console.log('一级导航', response.data);
  159. navigation1.value = response.data;
  160. console.log('111111111111111111111111111', navigation1[0]?.value.category_id);
  161. } catch (error) {
  162. console.error(error);
  163. }
  164. }
  165. // 新闻列表
  166. const newsList = useState("newsList", () => '');
  167. const newslists = async () => {
  168. try {
  169. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&catid=${articleId}`);
  170. // console.log(response.data.rows);
  171. newsList.value = response.data.rows;
  172. total.value = response.data.count;
  173. } catch (error) {
  174. console.error(error);
  175. }
  176. }
  177. //热点资讯
  178. const hotlistall = useState("hotlistall", () => "");
  179. const hotlist = async () => {
  180. try {
  181. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${2}&level=${4}&placeid=${1}`);
  182. console.log('热点资讯', response.data);
  183. for (let item of response.data) {
  184. console.log(item);
  185. item.count = 1;
  186. }
  187. hotlistall.value = response.data;
  188. } catch (error) {
  189. console.error(error);
  190. }
  191. }
  192. //资讯推荐1
  193. const news1 = useState("news1", () => "");
  194. const newslist1 = async () => {
  195. try {
  196. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  197. console.log('热点资讯', response.data);
  198. news1.value = response.data;
  199. } catch (error) {
  200. console.error(error);
  201. }
  202. }
  203. const news11 = useState("news11", () => "");
  204. const newslist11 = async () => {
  205. try {
  206. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  207. console.log('热点资讯', response.data);
  208. news11.value = response.data;
  209. } catch (error) {
  210. console.error(error);
  211. }
  212. }
  213. //资讯推荐2
  214. const news2 = useState("news2", () => "");
  215. const newslist2 = async () => {
  216. try {
  217. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  218. console.log('热点资讯', response.data);
  219. news2.value = response.data;
  220. } catch (error) {
  221. console.error(error);
  222. }
  223. }
  224. const news22 = useState("news22", () => "");
  225. const newslist22 = async () => {
  226. try {
  227. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  228. console.log('热点资讯', response.data);
  229. news22.value = response.data;
  230. } catch (error) {
  231. console.error(error);
  232. }
  233. }
  234. const name = useState("name", () => "");
  235. const name1 = async () => {
  236. try {
  237. const response = await axios.get(`/web/getOneWebsiteCategory?catid=${articleId}`);
  238. console.log('name11111111', response.data);
  239. name.value = response.data.name;
  240. navigateList()
  241. } catch (error) {
  242. console.error(error);
  243. }
  244. }
  245. //挂载成功钩子函数
  246. onMounted(() => {
  247. name1()
  248. // 资讯推荐
  249. newslists()
  250. // 热点资讯
  251. hotlist()
  252. // 资讯推荐
  253. newslist1()
  254. newslist2()
  255. // 热点资讯
  256. newslist11()
  257. newslist22()
  258. // navigateList()
  259. })
  260. //路由中间件
  261. definePageMeta({
  262. middleware: 'auth'
  263. })
  264. </script>
  265. <style lang="less" scoped>
  266. #newsList {
  267. width: 100%;
  268. overflow: hidden;
  269. }
  270. //导航条
  271. .breadcrumb {
  272. width: 100%;
  273. height: 22px;
  274. margin-bottom: 30px;
  275. font-family: Microsoft YaHei, Microsoft YaHei;
  276. font-weight: 400;
  277. font-size: 20px;
  278. color: #666666;
  279. line-height: 23px;
  280. text-align: left;
  281. font-style: normal;
  282. text-transform: none;
  283. margin-top: 40px;
  284. :deep(.el-breadcrumb) {
  285. display: inline-block;
  286. vertical-align: -4px;
  287. }
  288. :deep(.el-breadcrumb__inner a),
  289. :deep(.el-breadcrumb__inner.is-link) {
  290. color: #666666;
  291. font-weight: 400;
  292. text-decoration: none;
  293. transition: var(--el-transition-color);
  294. }
  295. span {
  296. font-family: Microsoft YaHei, Microsoft YaHei;
  297. font-weight: 400;
  298. font-size: 20px;
  299. color: #666666;
  300. line-height: 23px;
  301. text-align: left;
  302. font-style: normal;
  303. text-transform: none;
  304. }
  305. span:hover {
  306. color: #666666;
  307. }
  308. .location {
  309. margin-right: 20px;
  310. width: 100px;
  311. height: 22px;
  312. font-family: Microsoft YaHei, Microsoft YaHei;
  313. font-weight: 400;
  314. font-size: 20px;
  315. color: #666666;
  316. line-height: 23px;
  317. text-align: left;
  318. font-style: normal;
  319. text-transform: none;
  320. }
  321. }
  322. // 资讯列表
  323. .newsList {
  324. width: 100%;
  325. // height: 675px;
  326. overflow: hidden;
  327. margin-bottom: 70px;
  328. .inner {
  329. width: 1200px;
  330. .innerLeft,
  331. .innerRight {
  332. border-top: 1px solid #ccc;
  333. }
  334. .innerLeft {
  335. width: 820px;
  336. margin-right: 30px;
  337. .list {
  338. margin-bottom: 70px;
  339. li {
  340. width: 820px;
  341. padding: 15px 0;
  342. a{
  343. display: flex;
  344. justify-content: space-between;
  345. }
  346. .listTitle {
  347. // float: left;
  348. display: inline-block;
  349. width: 486px;
  350. white-space: nowrap;
  351. overflow: hidden;
  352. text-overflow: ellipsis;
  353. font-family: Microsoft YaHei, Microsoft YaHei;
  354. font-weight: 400;
  355. font-size: 20px;
  356. color: #333333;
  357. text-align: left;
  358. font-style: normal;
  359. text-transform: none;
  360. }
  361. .time {
  362. // float: right;
  363. font-family: Microsoft YaHei, Microsoft YaHei;
  364. font-weight: 400;
  365. font-size: 18px;
  366. color: #333333;
  367. }
  368. }
  369. >li:hover .listTitle {
  370. color: #a01c0e;
  371. }
  372. // >li:nth-child(1)::after,
  373. // >li:nth-child(2)::after {
  374. // content: "热";
  375. // margin-left: 13px;
  376. // background: #FF8A37;
  377. // color: #fff;
  378. // font-size: 14px;
  379. // padding: 0px 2px;
  380. // }
  381. >li:nth-child(5n) {
  382. border-bottom: 1px solid #D9D9D9;
  383. padding-bottom: 30px;
  384. }
  385. >li:nth-child(5n+1) {
  386. span {
  387. font-weight: bold;
  388. }
  389. font-weight: bold;
  390. padding-top: 30px;
  391. }
  392. }
  393. >.pagination {
  394. width: 800px;
  395. height: 34px;
  396. margin-left: 141px;
  397. display: flex;
  398. justify-content: center;
  399. margin: 0;
  400. // 鼠标移入后字体颜色
  401. .el-pagination::v-deep :hover {
  402. color: #a01c0e;
  403. }
  404. .el-pagination.is-background::v-deep .btn-next,
  405. .el-pagination.is-background::v-deep .btn-prev {
  406. width: 70px;
  407. height: 34px;
  408. margin: 0px 10px;
  409. border-radius: 4px;
  410. }
  411. .el-pagination.is-background::v-deep .el-pager li {
  412. margin: 0px 10px;
  413. width: 38px;
  414. height: 34px;
  415. border-radius: 4px;
  416. }
  417. .el-pagination.is-background::v-deep .btn-next.is-active,
  418. .el-pagination.is-background::v-deep .btn-prev.is-active,
  419. .el-pagination.is-background::v-deep .el-pager li.is-active {
  420. background-color: #a01c0e;
  421. color: #fff;
  422. }
  423. }
  424. }
  425. .innerRight {
  426. width: 350px;
  427. height: 1242px;
  428. border-bottom: 1px solid #ccc;
  429. // height: 605px;
  430. }
  431. }
  432. }
  433. //资讯推荐
  434. .zixuntuijian {
  435. width: 100%;
  436. height: 290px;
  437. margin-bottom: 70px;
  438. .innerLeft {
  439. // 左侧
  440. .zixunLeft {
  441. margin-right: 30px;
  442. }
  443. .zixunRight,
  444. .zixunLeft {
  445. float: left;
  446. width: 380px;
  447. height: 290px;
  448. // 标题部分
  449. >.title {
  450. width: 380px;
  451. }
  452. >.title>h3 {
  453. height: 36px;
  454. font-family: Source Han Sans, Source Han Sans;
  455. font-weight: bold;
  456. font-size: 24px;
  457. color: #000000;
  458. line-height: 28px;
  459. text-align: left;
  460. font-style: normal;
  461. text-transform: none;
  462. border-bottom: 1px solid #a01c0e;
  463. }
  464. >.title>h3>span {
  465. float: right;
  466. width: 56px;
  467. height: 20px;
  468. line-height: 24px;
  469. font-weight: 400;
  470. font-size: 14px;
  471. color: #999999;
  472. font-style: normal;
  473. text-transform: none;
  474. }
  475. .photo_text {
  476. >li:first-child {
  477. width: 380px;
  478. height: 120px;
  479. margin-top: 20px;
  480. margin-bottom: 15px;
  481. position: relative;
  482. >img {
  483. float: left;
  484. width: 160px;
  485. height: 120px;
  486. }
  487. >div {
  488. float: left;
  489. width: 220px;
  490. height: 120px;
  491. padding-left: 15px;
  492. padding-top: 6px;
  493. box-sizing: border-box;
  494. background-color: #f6f6f6;
  495. >h5 {
  496. width: 200px;
  497. height: 54px;
  498. display: -webkit-box;
  499. -webkit-box-orient: vertical;
  500. -webkit-line-clamp: 2;
  501. overflow: hidden;
  502. text-overflow: ellipsis;
  503. word-break: break-all;
  504. font-family: Source Han Sans, Source Han Sans;
  505. font-weight: 500;
  506. font-size: 18px;
  507. color: #333333;
  508. line-height: 26px;
  509. text-align: left;
  510. font-style: normal;
  511. text-transform: none;
  512. }
  513. >p {
  514. width: 200px;
  515. height: 22px;
  516. line-height: 20px;
  517. position: absolute;
  518. bottom: 5px;
  519. right: 0;
  520. >span {
  521. display: inline-block;
  522. // width: 100px;
  523. height: 18px;
  524. font-family: Source Han Sans, Source Han Sans;
  525. font-weight: 400;
  526. font-size: 12px;
  527. color: #999999;
  528. text-align: left;
  529. line-height: 14px;
  530. font-style: normal;
  531. text-transform: none;
  532. }
  533. >span:last-child {
  534. // width: 90px;
  535. text-align: right;
  536. margin-left: 20px;
  537. }
  538. }
  539. }
  540. }
  541. >li {
  542. width: 380px;
  543. height: 25px;
  544. white-space: nowrap;
  545. overflow: hidden;
  546. text-overflow: ellipsis;
  547. font-family: PingFang SC, PingFang SC;
  548. font-weight: 500;
  549. font-size: 18px;
  550. color: #333333;
  551. line-height: 21px;
  552. text-align: left;
  553. font-style: normal;
  554. text-transform: none;
  555. margin-bottom: 10px;
  556. em {
  557. display: inline-block;
  558. width: 8px;
  559. height: 8px;
  560. border-radius: 8px;
  561. margin-right: 10px;
  562. background-color: #d9d9d9;
  563. }
  564. }
  565. >li:hover {
  566. color: #a01c0e;
  567. }
  568. >li:hover em {
  569. background-color: #a01c0e;
  570. }
  571. }
  572. }
  573. }
  574. .innerRight {
  575. width: 381px;
  576. height: 290px;
  577. background-color: #fbfbfb;
  578. >.title {
  579. width: 380px;
  580. height: 40px;
  581. line-height: 40px;
  582. border-top: 1px solid #a01c0e;
  583. border-bottom: 1px solid #e7e7e7;
  584. >h4 {
  585. font-family: Microsoft YaHei, Microsoft YaHei;
  586. font-weight: 400;
  587. margin-left: 20px;
  588. font-size: 20px;
  589. color: #000000;
  590. text-align: left;
  591. font-style: normal;
  592. text-transform: none;
  593. >span {
  594. float: right;
  595. font-family: Microsoft YaHei, Microsoft YaHei;
  596. font-weight: 400;
  597. font-size: 14px;
  598. margin-right: 10px;
  599. color: #999999;
  600. text-align: left;
  601. font-style: normal;
  602. text-transform: none;
  603. }
  604. }
  605. }
  606. .rightList {
  607. height: 540px;
  608. margin-top: 20px;
  609. >li {
  610. height: 100px;
  611. margin-bottom: 10px;
  612. >img {
  613. width: 150px;
  614. height: 100px;
  615. }
  616. >p {
  617. width: 219px;
  618. height: 100px;
  619. padding-left: 12px;
  620. font-family: PingFang SC, PingFang SC;
  621. font-weight: 400;
  622. font-size: 16px;
  623. color: #333333;
  624. line-height: 22px;
  625. text-align: left;
  626. font-style: normal;
  627. text-transform: none;
  628. }
  629. >p:hover {
  630. box-shadow: 0 0 16px 1px rgba(0, 0, 0, 0.1);
  631. }
  632. }
  633. }
  634. }
  635. }
  636. </style>